package com.lwm.mybatis.custom.utils;

import com.lwm.mybatis.custom.cfg.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author liweimin
 * @date 2021/6/15 18:32
 * @since
 */
public class DataSourceUtil {
    /**
     * 获取一个连接
     *
     * @param configuration
     * @return
     */
    public static Connection createConnection(Configuration configuration) {
        Connection connection = null;
        try {
            Class.forName(configuration.getDriver());
            connection = DriverManager.getConnection(configuration.getUrl(), configuration.getUsername(), configuration.getPassword());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
        return connection;
    }
}
